package com.jy.web.diy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jy.web.diy.entity.CategoryEntity;
import com.jy.web.diy.service.JsonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jy.web.diy.dao.AttributeDao;
import com.jy.web.diy.entity.AttributeEntity;
import com.jy.web.diy.service.AttributeService;


@Service("attributeService")
public class AttributeServiceImpl extends ServiceImpl<AttributeDao, AttributeEntity> implements AttributeService {
    @Autowired
    private JsonService jsonService;

    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        Optional.ofNullable(idList).ifPresent(ids -> {
            ids.stream().forEach(diyAttributeId -> {
                jsonService.deleteByAttributeId(diyAttributeId);
            });
            LambdaQueryWrapper<AttributeEntity> attributeEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
            attributeEntityLambdaQueryWrapper.in(AttributeEntity::getId, idList);
            remove(attributeEntityLambdaQueryWrapper);
        });
        return true;
    }
}
